package com.shungen.realapigateway.config;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.cloud.gateway.route.RouteLocator;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class GatewayStartupListener implements ApplicationListener<ApplicationReadyEvent> {

    private final RouteLocator routeLocator;

    public GatewayStartupListener(RouteLocator routeLocator) {
        this.routeLocator = routeLocator;
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 获取所有的路由
        routeLocator.getRoutes().subscribe(route -> {
            log.info("路由ID: {}", route.getId());
            log.info("路由路径: {}", route.getPredicate().toString());
            log.info("路由目标URI: {}", route.getUri().toString());
        });
    }
}
